package admin.action.fruits;

import java.io.UnsupportedEncodingException;
import java.util.List;

import admin.service.fruits.PatentService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Patent;

public class PatentNameAction {
	
	private List<Patent> patents;
	private String name;
	private int flag;
	private int code;
	//当前页
	private int currentPage;
	//最后一页
	private int endPage;
	private int counts;

	public List<Patent> getPatents() {
		return patents;
	}

	public void setPatents(List<Patent> patents) {
		this.patents = patents;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String execute()
	{
		
		
		if(this.getCode()==1)
		{
			try {
				this.setName(new String(this.getName().getBytes("iso-8859-1"),"utf-8"));
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		int add=0;
		if(new PatentService().getCountPatentByName(this.getName())%Constant.pageSize!=0)
		{
			add=1;
		}
		
		ActionContext.getContext().put("flag", 2);
		this.setFlag(2);
		ActionContext.getContext().put("name", this.getName());
		this.setEndPage(new PatentService().getCountPatentByName(this.getName())/Constant.pageSize+add);
		this.setCounts(new PatentService().getCountPatentByName(this.getName()));
		System.out.println(this.getName());
		//通过名称来查找所有的专利
		patents=new PatentService().getSegregatePatentByName(this.getName(),
				(this.getCurrentPage()-1)*Constant.pageSize+1, Constant.pageSize);
		System.out.println("flag为"+this.getFlag());
		System.out.println("当前页为"+this.getCurrentPage());
		
		return "succ";
	}


}
